package com.focus.xyz.main.pages;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import com.focus.xyz.core.utils.Constants;
import com.gargoylesoftware.htmlunit.Page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/7/27.
 */
public class ApolloMemCenterPage extends BasePage{
    private Action action;
    @FindBy(id = "sideNav")
    private WebElement sideMenu;

    public ApolloMemCenterPage(WebDriver driver, Action action) {
        super(driver, action);
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void openMenu(String menuName) throws Exception{
        List<WebElement> menuList = sideMenu.findElements(By.xpath("dl/dd"));
        System.out.println(menuList.size());
        for(WebElement e : menuList){
            if(menuName.equals(e.getText().trim())){
                WebElement link = e.findElement(By.tagName(Constants.TAG_A));
                action.click(link);
                break;
            }
        }
    }

}
